import axios from "@/utils/axios/axios";

export function throttle<T extends (...args: any[]) => void>(fn: T, interval: number) {
    let lastTime = 0;
    return  (...args: Parameters<T>) => {
        const now = new Date().getTime();
        if (now - lastTime > interval) {
            lastTime = now;
            // eslint-disable-next-line prefer-spread
            fn.apply(undefined, args);
        }
    };
}

export function debounce<T extends (...args: any[]) => void>(fn: T, delay: number) {
    let timer: NodeJS.Timeout | null = null;
    return  (...args: Parameters<T>) => {
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(() => {
            // eslint-disable-next-line prefer-spread
            fn.apply(undefined, args);
        }, delay);
    };
}

// 导入axios

// 请求地址列表
export function getlist() {
    return axios({
        url: '/list'
    });
}

// 编辑地址
// obj:地址对象
export function edit(obj: any) {
    return axios({
        url: '/edit',
        params: obj
    });
}

// 新增地址
// obj:地址对象
export function add(obj: any) {
    return axios({
        url: '/add',
        params: obj
    });
}